<script setup>
import { ref, watch } from 'vue'
import FlightList from './FlightList.vue'
import Video from './Video.vue'
import QxxxPop from './QxxxPop.vue'
import { usePopStore } from '@/stores'
import { storeToRefs } from 'pinia'
const popStore = usePopStore()
const { RiseLand, XY } = storeToRefs(popStore)
const close = () => {
  RiseLand.value.showPop = false
  __g.camera.set(535044.517656, 2490617.622822, 5316.796875, -19.70006, -128.61528, 2)
}
const dialogPosition = ref([0, 0])
watch(
  RiseLand.value,
  (newVal) => {
    if (newVal) {
      dialogPosition.value = XY.value
    }
  },
  {
    deep: true
  }
)

const showFlight = ref(false)
const flightList = ref(null)
const lookFlight = () => {
  showFlight.value = !showFlight.value
  if (showFlight.value) {
    flightList.value.setData(RiseLand.value.popInfo.flightActivities)
  } else {
    flightList.value.close()
  }
}

const host = window.origin
const showVideo = ref(false)
const showQxxx = ref(false)
const video = ref(null)
const qxxx = ref(null)
const loolVideo = () => {
  showVideo.value = !showVideo.value
  if (showVideo.value) {
    video.value.setData(RiseLand.value.popInfo.videoUrl)
  } else {
    video.value.close()
  }
}
// 打开气象信息弹框
const loolQxxx = () => {
  showQxxx.value = !showQxxx.value
  if (showQxxx.value) {
    qxxx.value.show()
  } else {
    qxxx.value.close()
  }
}
</script>
<template>
  <transition
    appear
    name="custom-classes-transition"
    enter-active-class="animate__animated  animate__fadeIn"
    leave-active-class="animate__animated animate__faster  animate__fadeOut"
  >
    <!-- <div
      class="AirspacePop"
      ref="currentDom"
      :style="{
        left: dialogPosition[0] + 'px',
        top: dialogPosition[1] + 'px'
      }"
      v-if="RiseLand.showPop"
    > -->
    <div class="AirspacePop" ref="currentDom" v-if="RiseLand.showPop" v-drag>
      <p class="title">
        <span>起降点属性信息</span>
        <span @click="close"><img src="@img/pop/close_icon.png" alt="" /></span>
      </p>
      <div class="content">
        <div class="left">
          <p>
            <span>· <i>起降点名称</i> ：</span>
            <el-tooltip effect="dark" :content="RiseLand.popInfo.riseLandPoint" placement="top">
              <span>{{ RiseLand.popInfo.riseLandPoint }}</span>
            </el-tooltip>
          </p>
          <p>
            <span>· <i>起降点类型</i> ：</span>
            <el-tooltip effect="dark" :content="RiseLand.popInfo.riseLandPointType" placement="top">
              <span>{{ RiseLand.popInfo.riseLandPointType }}</span>
            </el-tooltip>
          </p>
          <p>
            <span>· <i>建设单位</i>：</span>
            <el-tooltip
              effect="dark"
              :content="RiseLand.popInfo.companyName"
              placement="top"
              v-if="RiseLand.popInfo.companyName"
            >
              <span>{{ RiseLand.popInfo.companyName }}</span>
            </el-tooltip>
            <span v-else>--</span>
          </p>
          <p>
            <span>· <i>规模尺寸</i>：</span>
            <span v-if="RiseLand.popInfo.size">{{ RiseLand.popInfo.size }}m</span>
            <span v-else>--</span>
          </p>
          <p>
            <span>· <i>经纬度</i>：</span>
            <el-tooltip
              effect="dark"
              :content="RiseLand.popInfo.long + ',' + RiseLand.popInfo.lat"
              placement="top"
              v-if="RiseLand.popInfo.long"
            >
              <span>{{ RiseLand.popInfo.long }},{{ RiseLand.popInfo.lat }}</span>
            </el-tooltip>

            <span v-else>--</span>
          </p>
        </div>
        <div class="right">
          <p class="top">
            <span @click="loolQxxx" :class="{ active: showQxxx }">气象信息</span>
            <span @click="loolVideo" :class="{ active: showVideo }">视频监控</span
            ><span @click="lookFlight" :class="{ active: showFlight }">航班列表</span>
          </p>
          <p class="bottom">
            <video
              controls
              muted
              v-if="RiseLand.popInfo.riseLandPoint == '鹍航智能飞行基地'"
              :src="host + '/poi/video.mp4'"
            ></video>
            <img v-else-if="RiseLand.popInfo.photo" :src="RiseLand.popInfo.photo" alt="" />
            <img v-else src="@img/pop/img.png" alt="" />
          </p>
        </div>
      </div>
    </div>
  </transition>
  <FlightList ref="flightList" @closeFlight="showFlight = false" />
  <Video ref="video" @closeVideo="showVideo = false" />
  <QxxxPop ref="qxxx" @closeQxxx="showQxxx = false" />
</template>
<style scoped lang="scss">
.AirspacePop {
  position: fixed;
  z-index: 9;
  top: 200px;
  left: 50%;
  width: 450px;
  height: 219px;
  background: url('@img/pop/airspace_bg.png');
  background-size: 100% 100%;

  .title {
    display: flex;
    padding: 10px 20px 10px 50px;
    align-items: center;
    font-size: 16px;
    justify-content: space-between;

    span:last-child {
      width: 18px;
      height: 18px;
      cursor: pointer;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .content {
    margin-top: 5px;
    padding: 12px;
    display: flex;
    font-size: 13px;

    .left {
      flex: 1;

      p {
        display: flex;
        margin-bottom: 10px;

        span:first-child {
          flex: 0 0 92px;
          color: #afebff;
          display: flex;
          align-items: center;
          i {
            display: inline-block;
            width: 100%;
            margin: 0 3px;
            text-align-last: justify;
            text-align: justify;
            font-style: normal;
          }
        }

        span:last-child {
          flex: 1;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        &.name {
          font-size: 14px;
        }
      }
    }

    .right {
      flex: 0 0 150px;
      margin-left: 5px;

      .top {
        display: flex;
        align-self: center;
        justify-content: space-between;
        font-size: 13px;

        span {
          width: 70px;
          height: 37px;
          line-height: 37px;
          text-align: center;
          background: url('@img/pop/btn_bg.png');
          background-size: 100% 100%;
          cursor: pointer;

          &.active {
            background: url('@img/pop/btn_active.png');
            background-size: 100% 100%;
          }
        }
      }

      .bottom {
        video,
        img {
          width: 100%;
        }
      }
    }
  }
}
</style>
